function varargout = GUI_pied(varargin)
%GUI_PIED MATLAB code file for GUI_pied.fig
%      GUI_PIED, by itself, creates a new GUI_PIED or raises the existing
%      singleton*.
%
%      H = GUI_PIED returns the handle to a new GUI_PIED or the handle to
%      the existing singleton*.
%
%      GUI_PIED('Property','Value',...) creates a new GUI_PIED using the
%      given property value pairs. Unrecognized properties are passed via
%      varargin to GUI_pied_OpeningFcn.  This calling syntax produces a
%      warning when there is an existing singleton*.
%
%      GUI_PIED('CALLBACK') and GUI_PIED('CALLBACK',hObject,...) call the
%      local function named CALLBACK in GUI_PIED.M with the given input
%      arguments.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help GUI_pied

% Last Modified by GUIDE v2.5 11-Jul-2018 23:00:52

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @GUI_pied_OpeningFcn, ...
                   'gui_OutputFcn',  @GUI_pied_OutputFcn, ...
                   'gui_LayoutFcn',  [], ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
   gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before GUI_pied is made visible.
function GUI_pied_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   unrecognized PropertyName/PropertyValue pairs from the
%            command line (see VARARGIN)

% Choose default command line output for GUI_pied
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

cla

%Show image of the sensor's positions
myImage = imread('image.png');
set(handles.axes2,'Units','pixels');
resizePos = get(handles.axes2,'Position');
%myImage= imresize(myImage, [resizePos(3) resizePos(3)]);
axes(handles.axes2);
imshow(myImage);
set(handles.axes2,'Units','normalized');

%initialise les données
Data = [];
handles.Data = Data;
disp(Data)
guidata(hObject, handles)

%charges les données dernièrement sauvegardées
disp(1)
Data = handles.Data;
disp(2)
load('GUI','Data')
disp(3)
handles.Data = Data;

%set(handles.Data);
guidata(hObject, handles)

% UIWAIT makes GUI_pied wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = GUI_pied_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in Charger_pushbutton.
function Charger_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to Charger_pushbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%Initilalise les données 
Data = [];
handles.Data = Data;
disp(Data)
guidata(hObject, handles)

%charges les données dernièrement sauvegardées
disp(1)
Data = handles.Data;
disp(2)
load('GUI','Data')
disp(3)
handles.Data = Data;

%set(handles.Data);
guidata(hObject, handles)


% --- Executes on button press in Sauvegarder_pushbutton.
function Sauvegarder_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to Sauvegarder_pushbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
disp(1)
Data = handles.Data;
disp(2)
save('GUI','Data')
disp(3)
handles.Data = Data;

%Enregister les données pour les passer entre les fonctions
guidata(hObject, handles)


% --- Executes on button press in Analyse_pushbutton.
function Analyse_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to Analyse_pushbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
disp(1)
Data = handles.Data;
disp(2)
[ Data ] = Pied_droit(Data);
disp(3)
handles.Data = Data;

%set(handles.Data);
guidata(hObject, handles)


% --- Executes on button press in Affichage_pushbutton.
function Affichage_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to Affichage_pushbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
disp(1)
Data = handles.Data;
disp(2)

%chargement des données
a = Data.Pied.a;
Temps_DLO_droit = Data.Capteur(a).Pied.Temps.DLO ;
Temps_LTO_droit = Data.Capteur(a).Pied.Temps.LTO ;
Temps_TT_droit = Data.Capteur(a).Pied.Temps.TT ;
Temps_TP_droit = Data.Capteur(a).Pied.Temps.TP ;
Second_dshort = Data.Capteur(a).Pied.Second;
AccX_d = Data.Capteur(a).Pied.Acc.X ;
AccY_d = Data.Capteur(a).Pied.Acc.Y ;
AccZ_d = Data.Capteur(a).Pied.Acc.Z ;
AccZg_DLO_droit = Data.Capteur(a).Pied.AccZ.DLO ;
AccZg_LTO_droit = Data.Capteur(a).Pied.AccZ.LTO ;
AccZg_TT_droit = Data.Capteur(a).Pied.AccZ.TT ;
AccZg_TP_droit = Data.Capteur(a).Pied.AccZ.TP ;

% Create axes
axe = handles.axes1;
axes(axe);

cla(axe,'reset');

hold on
plot(Second_dshort,AccX_d)
plot(Second_dshort,AccY_d)
plot(Second_dshort,AccZ_d)

plot(Temps_DLO_droit,AccZg_DLO_droit, 'mo', 'linewidth',1.25)
plot(Temps_LTO_droit,AccZg_LTO_droit,'md', 'linewidth',2)
plot(Temps_TT_droit, AccZg_TT_droit,'ms', 'linewidth',2)
plot(Temps_TP_droit,AccZg_TP_droit, 'mx','linewidth',2)

hold off
legend('Accélération en X','Accélération en Y', 'Accélération en Z', 'Levé des orteils','Décollement des orteils', 'Touché du talon','Touché de la plante de pied');
legend('location','bestoutside')
set(gca,'YGrid','on', 'Fontsize', 12)
title('Capteur sur les orteils','FontSize', 14)
ylabel('Accélération (g)','FontSize', 14)
xlabel('Secondes (s)','FontSize', 14)

disp(3)
handles.Data = Data;
guidata(hObject, handles)


% --- Executes on button press in Affichage_gyr_pushbutton.
function Affichage_gyr_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to Affichage_gyr_pushbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
disp(1)
Data = handles.Data;
disp(2)


%chargement des données
a = Data.Pied.a;
GyrY_DLO_droit = Data.Capteur(a).Pied.GyrY.DLO;
GyrY_LTO_droit = Data.Capteur(a).Pied.GyrY.LTO ;
GyrY_TT_droit = Data.Capteur(a).Pied.GyrY.TT ;
GyrY_TP_droit = Data.Capteur(a).Pied.GyrY.TP ;
Temps_DLO_droit = Data.Capteur(a).Pied.Temps.DLO ;
Temps_LTO_droit = Data.Capteur(a).Pied.Temps.LTO ;
Temps_TT_droit = Data.Capteur(a).Pied.Temps.TT ;
Temps_TP_droit = Data.Capteur(a).Pied.Temps.TP ;
Second_dshort = Data.Capteur(a).Pied.Second;
AccZg_TT_droit = Data.Capteur(a).Pied.AccZ.TT ;
AccZg_TP_droit = Data.Capteur(a).Pied.AccZ.TP ;
GyrX_d = Data.Capteur(a).Pied.Gyr.X ;
GyrY_d = Data.Capteur(a).Pied.Gyr.Y ;
GyrZ_d = Data.Capteur(a).Pied.Gyr.Z ;

% Create axes
axe = handles.axes1;
axes(axe);

cla(axe,'reset');

hold on
plot(Second_dshort, GyrX_d)
plot(Second_dshort,GyrY_d)
plot(Second_dshort, GyrZ_d)
plot(Temps_DLO_droit,GyrY_DLO_droit, 'mo', 'linewidth',1.25)
plot(Temps_LTO_droit,GyrY_LTO_droit, 'md','linewidth',1.25)
plot(Temps_TT_droit, AccZg_TT_droit,'ms', 'linewidth',2)
plot(Temps_TP_droit,AccZg_TP_droit, 'mx', 'linewidth',2) 

hold off
legend('Rotation autour de X','Rotation autour de Y', 'Rotation autour de Z', 'Levé des orteils','Décollement des orteils', 'Touché du talon','Touché de la plante de pied');
legend('location','bestoutside')
set(gca,'YGrid','on', 'Fontsize', 12)
title('Capteur sur les orteils, Pied','FontSize', 14)
ylabel('Vitesse angulaire (deg/s)','FontSize', 14)
xlabel('Secondes (s)','FontSize', 14)

disp(3)
handles.Data = Data;
guidata(hObject, handles)

